from pyramid.config import Configurator
from sqlalchemy import engine_from_config
from .models import DBSession, Base


def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    config = Configurator(settings=settings)
    config.include('pyramid_jinja2')
    config.add_jinja2_renderer(".html")
    config.add_route('list', '/')
    config.add_route('index', '/new')
    config.add_route('add', '/add')
    config.add_route('show', '/show/{id}')
    config.add_route('update', '/update')
    config.add_route('delete', '/delete/{id}')
    config.scan('.views')
    return config.make_wsgi_app()
